/*
 *     This file is part of Mobile GPS Logger.
 *
 *     Mobile GPS Logger is free software: you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation, either version 3 of the
 *     License, or (at your option) any later version.
 *
 *     Mobile GPS Logger is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License v3 for more details.
 *
 *     You should have received a copy of the GNU General Public License v3
 *     along with Mobile GPS Logger. If not, see <http://www.gnu.org/licenses/>.
 */

package cx.ath.skyflyer.gpslog.util;

import java.util.NoSuchElementException;

/**
 *
 * @author Ahti Legonkov
 */
public class Queue {

    public Queue() {
        head = tail = new Item();
    }

    public void push(Object o) {
        tail.value = o;
        tail.next = new Item();
        tail = tail.next;
    }

    public Object pop() throws NoSuchElementException {
        if (this.isEmpty())
            throw new NoSuchElementException();

        Object res = head.value;
        head = head.next;
        return res;
    }

    public boolean isEmpty() {
        return head == tail;
    }

    private class Item {
        public Item next;
        public Object value;

        public Item() {
            this(null, null);
        }

        public Item(Item next, Object value) {
            this.next = next;
            this.value = value;
        }
    }

    private Item head;
    private Item tail;
}
